package com.bosicloud.cmb.ibp.commom.hystrix;


import com.netflix.hystrix.HystrixCommand;
import com.netflix.hystrix.exception.HystrixRuntimeException;
import org.aspectj.lang.ProceedingJoinPoint;

/**
 * @author Jack Peng / ziliang.peng@bosicloud.com
 */
public class IBPCommand extends HystrixCommand<Object> {

    private ProceedingJoinPoint joinPoint;

    public IBPCommand(Setter setter, ProceedingJoinPoint joinPoint, String fallbackName) {
        super(setter);
        this.joinPoint = joinPoint;
    }

    @Override
    protected Object run() throws Exception {
        try {
            return joinPoint.proceed();
        } catch (Throwable throwable) {
            throw new HystrixRuntimeException(HystrixRuntimeException.FailureType.COMMAND_EXCEPTION, IBPCommand.class, throwable.getMessage(), new Exception(throwable), null);
        }
    }

    @Override
    protected Object getFallback() {
        return super.getFallback();
    }
}
